package com;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class PushCallBack implements MqttCallback {

    /**
     * mqtt连接丢失时触发（不包括主动disconnect）
     * @param throwable
     */
    @Override
    public void connectionLost(Throwable throwable) {
        System.out.println("连接失败，可做重连");
    }

    /**
     * 收到订阅消息后调用
     * @param s
     * @param mqttMessage
     * @throws Exception
     */
    @Override
    public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
        System.out.println("---------------------------");
        System.out.println("接收到的主题为：" + s);
        System.out.println("接收到的消息为：" + new String(mqttMessage.getPayload()));
    }

    /**
     * 发布消息完成后调用
     * @param iMqttDeliveryToken
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        System.out.println("---------------------------");
        System.out.println("广播完成");
    }
}
